<?php session_start();
include_once("../config.php");
include_once(ROOT_DIR_CLASES.'/cCliente.php');
include_once(ROOT_DIR_CLASES.'/log.php');
include_once(ROOT_DIR_CLASES.'/posiMovil.php');
include_once(ROOT_DIR_CLASES.'/cLogin.php');
include_once(ROOT_DIR_CLASES.'/PHPLogger.php');
include_once('../JSON.php');
if (!isset($_SESSION['cliente'])) {
  		log::errorJS('Sesion expirada...');
  		exit();
  	}

	$LOGIN = unserialize($_SESSION['loginClass']);
	$json = new Services_JSON();
	$loginJSON = $json->encode($LOGIN);
	$LOGGER = new PHPLogger(LOGGER_PATH, LOGGER_LEVEL);

	/************************************************************************
	CONFIGURACION INICIAL
	*************************************************************************/
		//include("config.php");
		include_once(ROOT_DIR_CLASES.'/cResultado.php');
		include_once(ROOT_DIR_CLASES.'/cConfiguracion.php');
  		include_once(ROOT_DIR_CLASES.'/MiConfig.php');
		$cta 		= $LOGIN->cuentaFk;
		$iObjetivo 	= $LOGIN->objetivoDB;
		$esFlota 	= '0';
		if ($LOGIN->objetivoDB == 3){
			$esFlota = '1';
		}
		if ($LOGIN->objetivo == 4){
			$cta = $LOGIN->tablaId;
			$iObjetivo = $LOGIN->objetivo;
		}

		$configRegistrada = cConfiguracion::getConfig($cta, $iObjetivo);
		$miConfig = new MiConfig();
		//Puntos
		$puntosVisibles = cConfiguracion::getPuntosVisibles($cta, $iObjetivo);
		for($i = 0;  $i < $puntosVisibles->cantidad(); $i++ ) {
			$miConfig->putPuntoId($puntosVisibles->campo('PUNTO_ID',$i));
		}
		//Zonas
		$zonasVisibles = cConfiguracion::getZonasVisibles($cta, $iObjetivo);
		for($i = 0;  $i < $zonasVisibles->cantidad(); $i++ ) {
			$miConfig->putZonaId($zonasVisibles->campo('ZONA_ID',$i));
		}

		if ($configRegistrada->cantidad()>0){ //tiene configuracion inicial
			$miConfig->id = $configRegistrada->campo('ORDER_ID',0);
			//Vehiculo
			$miConfig->VEHlblformat = $configRegistrada->campo('VEH_lblformat',0);
			if (trim($miConfig->VEHlblformat)=='')
				$miConfig->VEHlblformat = VEH_LBLFORMAT;
			$miConfig->CMDtimeout = $configRegistrada->campo('CMD_timeout',0);
			if (trim($miConfig->CMDtimeout)=='')
				$miConfig->CMDtimeout = CMD_TIMEOUT;

			$miConfig->VEHsimpleview = $configRegistrada->campo('VEH_simpleview',0);
			if (trim($miConfig->VEHsimpleview)=='')
				$miConfig->VEHsimpleview = VEH_SIMPLEVIEW;
			$miConfig->VEHlblmapformat = $configRegistrada->campo('VEH_lblmapformat',0);
			if (trim($miConfig->VEHlblmapformat)=='')
				$miConfig->VEHlblmapformat = VEH_LBLMAPFORMAT;
			$miConfig->VEHlblcolor = $configRegistrada->campo('VEH_lblcolor',0);
			if (trim($miConfig->VEHlblcolor)=='')
				$miConfig->VEHlblcolor = VEH_LBLCOLOR;
			$miConfig->VEHlblsize = $configRegistrada->campo('VEH_lblsize',0);
			if (trim($miConfig->VEHlblsize)=='')
				$miConfig->VEHlblsize = VEH_LBLSIZE;
			$miConfig->VEHradio = $configRegistrada->campo('VEH_radio',0);
			if (trim($miConfig->VEHradio)=='')
				$miConfig->VEHradio = VEH_RADIO;
			$miConfig->VEHtransparencia = $configRegistrada->campo('VEH_transparencia',0);
			if (trim($miConfig->VEHtransparencia)=='')
				$miConfig->VEHtransparencia = VEH_TRANSPARENCIA;

			//Historico
			$miConfig->HIScolor = $configRegistrada->campo('HIS_color',0);
			if (trim($miConfig->HIScolor)=='')
				$miConfig->HIScolor = HIS_COLOR;
			$miConfig->HISthickness = $configRegistrada->campo('HIS_thickness',0);
			if (trim($miConfig->HISthickness)=='')
				$miConfig->HISthickness = HIS_THICKNESS;
			$miConfig->HISversentido = $configRegistrada->campo('HIS_sentido',0);
			if (trim($miConfig->HISversentido)=='')
				$miConfig->HISversentido = HIS_VERSENTIDO;
			$miConfig->HISvelexceso = $configRegistrada->campo('HIS_exceso',0);
			if (trim($miConfig->HISvelexceso)=='')
				$miConfig->HISvelexceso = HIS_VELEXCESO;
			$miConfig->HISfiltrocero = $configRegistrada->campo('HIS_filtrocero',0);
			if (trim($miConfig->HISfiltrocero)=='')
				$miConfig->HISfiltrocero = HIS_FILTROCERO;
		}
		else{ //no tiene configuracion inicial .:. levanto la configuracion por defecto...
			$miConfig->id = '';
			//Vehiculo
			$miConfig->VEHlblformat = VEH_LBLFORMAT;
			$miConfig->CMDtimeout = CMD_TIMEOUT;
			$miConfig->VEHsimpleview = VEH_SIMPLEVIEW;
			$miConfig->VEHlblmapformat = VEH_LBLMAPFORMAT;
			$miConfig->VEHlblcolor = VEH_LBLCOLOR;
			$miConfig->VEHlblsize = VEH_LBLSIZE;
			$miConfig->VEHradio = VEH_RADIO;
			$miConfig->VEHtransparencia = VEH_TRANSPARENCIA;
			//Historico
			$miConfig->HIScolor = HIS_COLOR;
			$miConfig->HISthickness = HIS_THICKNESS;
			$miConfig->HISversentido = HIS_VERSENTIDO;
			$miConfig->HISvelexceso = HIS_VELEXCESO;
			$miConfig->HISfiltrocero = HIS_FILTROCERO;
	}
	
?>
<script type="text/javascript" >
	var VEH_SIMPLEVIEW = <?=$miConfig->VEHsimpleview ?>;
	var MOVILES_SELECCIONADOS = '';

	var properties = null;
	var cuentaSelectSegui = <?="'".$_GET['cuentaSelectSegui']."'"?>;
	var cuentaSelectSelection = '-1';
	<? if (isset($_GET['cuentaSelectSelection'])) {?> cuentaSelectSelection = <?="'".$_GET['cuentaSelectSelection']."'"?> <? } ?>;

	var cuentaSelectTablero = '-1';
	<? if (isset($_GET['cuentaSelectTablero'])) {?> cuentaSelectTablero = <?="'".$_GET['cuentaSelectTablero']."'"?> <? } ?>;
	
	var misVehiculos_limitView = <?= LIMIT_VIEWMOVILES ?>;
	var misVehiculos_limitMonitor = <?= LIMIT_LISTMONITOR ?>;
	var misVehiculos_loteo = <?= LOTE_MOVILES ?>;

	var MAXMOVILCERCA = <?= MAXMOVILCERCA ?>;

	<? if (isset($_GET['movilesSELECTED'])) {?>
		MOVILES_SELECCIONADOS = <?="'".$_GET['movilesSELECTED']."'"?> ;
	<? } ?>;
	var MOVILES_MONITOR = '';
	<? if (isset($_GET['movilesMONITOR'])) {?>
		MOVILES_MONITOR = <?="'".$_GET['movilesMONITOR']."'"?> ;
	<? } ?>;
	var MOVILES_VISIBLES = cuentaSelectSegui;
	<? if (isset($_GET['movilesVISIBLES'])) {?>
		MOVILES_VISIBLES = <?="'".$_GET['movilesVISIBLES']."'"?> ;
	<? } ?>;
	
</script>


<script src="../js/gmap.js" type="text/javascript"></script>
<script src="../js/minimenu.js" type="text/javascript"></script>
<script src="../js/myClass/MyClass.js" type="text/javascript"></script>
<script src="../js/myClass/MyUtils.js" type="text/javascript"></script>
<script src="../js/myClass/MyAjax.js" type="text/javascript"></script>
<script src="../js/myClass/MySortArray.js" type="text/javascript"></script>
<script src="../js/myClass/MyValidator.js" type="text/javascript"></script>
<script src="../js/miniMenu/MiniMenu.js" type="text/javascript"></script>
<link rel="stylesheet" href="../js/miniMenu/miniMenu.css" type="text/css"/>
<link rel="stylesheet" href="../js/componentes/MonitorContainer.css" type="text/css"/>
<link rel="stylesheet" href="../js/componentes/MonitorButton.js" type="text/css"/>
<link href="../styles/minimenu.css" rel="stylesheet" type="text/css">
<link href="../styles/gmap.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="../js/md5.js"></script>
<script language="javascript" src="../js/browserdetect.js"></script>
<script language="javascript" src="../js/json.js"></script>
<script language="javascript" src="../js/jshashtable.js"></script>
<script language="javascript" src="../openlayers/OpenLayers.js"></script>
<script src="../js/DinamicIncludes_Map.js" type="text/javascript"></script>
<script language="javascript" src="../js/MMapPanels/vehiculos2.js"></script>
<script language="javascript" src="../js/MMapSidebars/monitor.js"></script>


<div id="OpenLayers.Control.MonitorContainer_228_containerDiv" class="OpenContainer" unselectable="on">
	<div class="OpenContainer-header" style="text-align: left;">
		<div class="OpenContainer-image"><span class="OpenContainer-title">Monitor</span></div>
	</div>
	<div class="OpenContainer-container" style="height: 100%; overflow: hidden;">
		<div style="display: block; overflow: hidden;" id="monitor_content"> 
			<div id="minimenuMonitorContent" class="minimenu">
		                <div class="buttonBar">
			            	<input type="button" onmouseout="minimenuInfoSet('minimenuMonitorContent', '');" onmouseover="minimenuInfoSet('minimenuMonitorContent', 'Seleccionar todos los eventos');" onclick="checkAllOptions('boxEventos[]', true);" class="BTNselectAll">
							<input type="button" onmouseout="minimenuInfoSet('minimenuMonitorContent', '');" onmouseover="minimenuInfoSet('minimenuMonitorContent', 'No seleccionar ningun evento');" onclick="checkAllOptions('boxEventos[]', false);" class="BTNunselectAll">
		                    <input type="button" onmouseout="minimenuInfoSet('minimenuMonitorContent', '');" onmouseover="minimenuInfoSet('minimenuMonitorContent', 'Procesar todos los eventos seleccionados');" onclick="openPopUpLeerEventosSelected();" class="BTNprocessAll">
		                    <input type="button" onmouseout="minimenuInfoSet('minimenuMonitorContent', '');" onmouseover="minimenuInfoSet('minimenuMonitorContent', 'Borrar todas las marcas de eventos del monitor impresas en el mapa');" onclick="clearEventosMonitorFromMap();" class="BTNcancel">
		                </div>    
		                <div class="infoBar"></div>
		    </div>
			<div style="overflow: auto; width: 100%; background: none repeat scroll 0% 0% rgb(227, 227, 227); height: 130px;" id="monitorListScroll">
		    	<div id="divMonitorList"></div>
		    </div>
		</div>
	</div>
</div>

<script type="text/javascript" >
	var VEH_SIMPLEVIEW = <?=$miConfig->VEHsimpleview ?>;
	CargarEventosMonitor();
</script>